package com.chenfei.page.service.impl;

import com.chenfei.page.domain.Test;
import com.chenfei.page.entity.PageBean;
import com.chenfei.page.mapper.TestMapper;
import com.chenfei.page.service.PageService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PageServiceImpl implements PageService {
    @Autowired
    PageHelper pageHelper;
    @Autowired
    TestMapper testMapper;

    public List<Test> findTestByPage(int currentPage, int pageSize) {
        //设置分页信息，分别是当前页数和每页显示的总记录数【记住：必须在mapper接口中的方法执行之前设置该分页信息】
        PageHelper.startPage(currentPage, pageSize);
        //全部商品
        List<Test> allItems = testMapper.findAll();
        //总记录数
        int countNums = testMapper.countTest();
        PageBean<Test> pageData = new PageBean<>(currentPage, pageSize, countNums);
        pageData.setItems(allItems);
        return pageData.getItems();
    }
}
